package com.hengpeng.itfin.persist.impl;

import org.springframework.stereotype.Repository;

import com.hengpeng.common.persist.AbstractDao;
import com.hengpeng.common.persist.entity.AbstractEntity.BoolValue;
import com.hengpeng.common.persist.query.DynamicQuery;
import com.hengpeng.common.persist.query.Restrictions;
import com.hengpeng.itfin.persist.UserInfoDao;
import com.hengpeng.itfinbase.persist.UserInfo;

/**
 * 资金账户持久层实现类
 * @author zhaojitao
 * @version 1.0, 2010-8-3
 */
@Repository
public class UserInfoDaoImpl extends AbstractDao<UserInfo> implements UserInfoDao
{

	@Override
	public UserInfo getUserByUserName(String userName)
	{
		DynamicQuery query = new DynamicQuery(UserInfo.class);
		query.eq("userName", userName);
		return super.getSingleByDynamicQuery(query);
	}

	@Override
	public UserInfo getUserByUserNameEmailMobile(String s) {
		DynamicQuery query = new DynamicQuery(UserInfo.class);
		query.add(Restrictions.or(Restrictions.eq("userName", s), 
				Restrictions.eq("mobile", s), Restrictions.eq("email", s)));
		return super.getSingleByDynamicQuery(query);
	}

	@Override
	public UserInfo getUserByTrustAccountId(String trustAccountId)
	{
		DynamicQuery query = new DynamicQuery(UserInfo.class);
		query.eq("trustAccountId", trustAccountId);
		return super.getSingleByDynamicQuery(query);
	}

	@Override
	public UserInfo getUserByBusiCode(String busiCode)
	{
		DynamicQuery query = new DynamicQuery(UserInfo.class);
		query.eq("busiCode", busiCode);
		return super.getSingleByDynamicQuery(query);
	}
	
	@Override
	public UserInfo getUserByMobile(String mobile){
		DynamicQuery query = new DynamicQuery(UserInfo.class);
		query.eq("mobile", mobile);
		return super.getSingleByDynamicQuery(query);
	}

	@Override
	public int updateUserInfo(String cardNumber, String trustAccountId,
			String mobile, String email, String realName,
			BoolValue newIsOpenAccount, Long id, BoolValue oldIsOpenAccount) {
		return super.exeNamedQuery("userInfo.updateUserInfo", new Object[] { cardNumber, trustAccountId,
				 mobile,email,realName, newIsOpenAccount,  id, oldIsOpenAccount});
	}
	
}
